﻿var status = 0;
var random = java.lang.Math.floor(Math.random() * 4);
var eff = "#fEffect/CharacterEff/1082565/2/0#";
var vvv = "#fUI/Basic/BtHide3/mouseOver/0#";
var vvv4 = "#fUI/UIWindow4/PQRank/rank/gold#";
var z1 = "#fEffect/ItemEff/1112811/0/0#";//黄金音符
var z5 = "#fEffect/CharacterEff/1112904/2/1#";//五角花
var z6 = "#fMap/MapHelper.img/weather/2011Xmas/3#";//粉色小天使
var z7 = "#fMap/MapHelper.img/weather/2011Xmas/6#";//白色小天使
var z10 = "#fMap/MapHelper.img/weather/2011Xmas/5#";//圣诞天使
var z8 = "#fMap/MapHelper.img/weather/gold/0#";//金蘑菇
var z9 = "#fMap/MapHelper.img/weather/WorldRecord1/9#";//小蓝光
var z11 = "#fMap/MapHelper.img/weather/WorldRecord2/0#";//星
var z12 = "#fMap/MapHelper.img/weather/present/1#";//礼物绿
var z13 = "#fMap/MapHelper.img/weather/present/0#";//礼物红
cztp = 0;
function start() {
    status = -1;
    action(1, 0, 0);
}

function action(mode, type, selection) {
    if (status == 0 && mode == 0) {
        cm.dispose();
        return;
    }
    if (mode == 1) {
        status++;
    } else {
        status--;
    }
    if (status == 0) {
        var txt ="#r#e- PPMS冒险岛·赞助中心"+"#k\r\n";	
        txt += "#r"+"- PPMS申明：本服无强制性消费玩家可酌情赞助我们"+"\r\n";
		txt += "#r"+"- 赞助教程：请先充值PPMS币然后用PPMS币兑换点卷\r\n";	
		txt += "#r"+"- 赞助比例：#k1人民币等于1PPMS币等于1000点卷\r\n";	
        txt += "#b#e#L4#"+"#k使用#bPPMS币#k兑换#r点卷"+"#l"+"\r\n";		
        txt += "#b#e#L2#"+"#k累计#b赞助#r礼包领取"+"#l"+"\r\n";
		txt += "#b#e#L1#"+"#k自愿#b赞助我们并#r打开本服赞助地址"+"#l";
        cm.sendSimple(txt);
    } else if (status == 1) {
        switch (selection) {
            case 0://抽奖
                cm.dispose();
                //cm.sendOk("\r\n\r\n\t\t\t#e#r修复细节问题");
               cm.openNpc(9900002, "mrpg");
                break;
            case 1://充值
                cm.dispose();
                 //cm.openWeb("http://www.baidu.com");
                 cm.sendOk("#d已自动为您打开充值链接，请输入账号密码进行充值，请确保账号内有角色到达10级，否则无法收到余额。");
                ////cm.openWeb("http://sae.kmmmhh.com?g=1720");
                break;
            case 2://累计充值
                cm.dispose();
                //cm.sendOk("\r\n\r\n\t\t\t#e#r敬请期待");
                cm.openNpc(1540861, "累计充值");
                break;
            case 3://中介系统
			cm.dispose();
			cm.openNpc(9310362, "41");
                break;
            case 4://金额点卷
                cztp = 1;
                var revenue0 = cm.getHyPay(1);
                var text = z1 + z1 + z1 + z1 + z1 + z1 + z1 + z1 + z1 + z1 + z1 + z1 + z1 + z1 + z1 + z1 + z1 + z1 + z1 + "\r\n\r\n";
                text += "#d   - 尊敬的玩家 #r#h ##d 在这里可以用PPMS币兑换点卷\r\n\r\n";
                text += "   - 当前玩家持有PPMS币：#r" + revenue0.formatMoney(0, "") + "#d 枚\r\n";
                text += "#r#L0#- 立刻使用PPMS币兑换点卷 " + "#l\r\n\r\n";
                text += z1 + z1 + z1 + z1 + z1 + z1 + z1 + z1 + z1 + z1 + z1 + z1 + z1 + z1 + z1 + z1 + z1 + z1 + z1 + "\r\n";
                cm.sendYesNoS(text, 2);
                break;
            case 5://余额商城
                cm.dispose();
                cm.openNpc(9310070, "zpjb1");
                break;
            case 6://余额礼包
                cm.dispose();
                cm.openNpc(9000111,"yelb");
                break;

        }
    } else if (status == 2) {
        if (cztp == 1) {
            switch (selection) {
                case 10://金额充值点卷
                    if (cm.getHyPay(1) < 1) {
                        cm.sendOk("#r#e抱歉 ！您的余额数目 [0] 不能进行充值 ");
                        status = -1;
                    } else {
                        var revenue0 = cm.getHyPay(1);
                        cm.sendGetText("#r#e★★★★★★★★★『充值中心』★★★★★★★★★#d\r\n\r\n请入你需充值点卷的数量 [ 1：3000 ]\r\n\r\n当前 [ #r#h ##d ] 玩家持有金额：" + revenue0.formatMoney(0, "") + " 元\r\n\r\n#k ");
                    }
                    break;
            case 0://理财系统
                cm.dispose();
                cm.openNpc(9000111,"yue");
                break;
            }
        }
    } else if (status == 3) {
        if (cm.getHyPay(1) - cm.getText() < 0) {
            cm.sendOk("#r#e抱歉 ！充值后余额低于 [ 0 ] ");
            cm.dispose();
        } else {
            cm.addHyPay(+cm.getText());
            cm.gainNX(cm.getText() * 3000);
            cm.sendOk("#d#e恭喜您\r\n\r\n购买点卷数量：#r" + cm.getText() * 3000 + "#k#n\r\n ");
            cm.dispose();

        }
    }
}

Number.prototype.formatMoney = function (places, symbol, thousand, decimal) {
    places = !isNaN(places = Math.abs(places)) ? places : 2;
    symbol = symbol !== undefined ? symbol : "　";
    thousand = thousand || ",";
    decimal = decimal || ".";
    var number = this,
        negative = number < 0 ? "-" : "",
        i = parseInt(number = Math.abs(+number || 0).toFixed(places), 10) + "",
        j = (j = i.length) > 3 ? j % 3 : 0;
    return symbol + negative + (j ? i.substr(0, j) + thousand : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousand) + (places ? decimal + Math.abs(number - i).toFixed(places).slice(2) : "");
};
